local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHOLYBUIBase());
local CallBackManager = ClientOHOH.load.CallBackManager();
local CommonOHOH =_G.CommonOHOH;

function InitInsts(ui)
    ui.insts = {};
    ui.insts.Close = "ctrl.close";
    ui.insts.Buy ={
        btn= "ctrl.btn.buy",
        price= "ctrl.btn.price",
    }
    ui.insts.Free= {
        btn="ctrl.btn.free",
        count="ctrl.btn.free_count"
    }
    ui.insts.Task= {
        title="ctrl.progress.title",
        onLineTime="ctrl.progress.time",
        progress="ctrl.progress.bar",
    }

    ui.insts.Pet= {
        [1]="ctrl.pet.1",
        [2]="ctrl.pet.2",
        [3]="ctrl.pet.3",
        [4]="ctrl.pet.4",
    }

    ui.insts.eggName="ctrl.eggName"

end;


function M.new(...)
	return M(...);
end;

function M.ctor(self)
    InitInsts(self);
    M.super.ctor(self, ClientOHOH:GetPath_Loop("ReplicatedStorage.Resource.UI.OpEggGui"));

    
    self.FreeEvent=_G.CommonOHOH.load.Connect().new()
    self.BuyEvent=_G.CommonOHOH.load.Connect().new()

    CallBackManager:AddRbxConnect(self,self.insts.Close.Activated, function()
        self:Hide();
	end);

    CallBackManager:AddRbxConnect(self,self.insts.Buy.btn.Activated, function()
        self.BuyEvent:Action()
	end);

    CallBackManager:AddRbxConnect(self,self.insts.Free.btn.Activated, function()
        self.FreeEvent:Action()
	end);
end;

--初始化
function M.Init(self,count,eggName,price,petIdList,...)
    for k,petId in pairs(petIdList) do
        local guid=petId.."_"..k
       ClientOHOH.load.PetCell().new(petId,guid,self.insts.Pet[k],...)
    end
    self.insts.Buy.price.Text=price
    self.insts.eggName.Text=eggName
    self.Count=count
    self:FullText(self.insts.Task.title,{count})
end


-- local TweenHelper = CommonOHOH.load.TweenHelper();
-- local tw1 = TweenInfo.new(1, Enum.EasingStyle.Linear,Enum.EasingDirection.Out);

-- -- 更新时间进度
-- function M.UpdateTimeByMins(self,now)
--     self.insts.onLineTime.Text=now.."/"..self.Count
--     TweenHelper:PlayTween(self.insts.Task.progress, tw1, {
--         Size=UDim2.fromScale(now/self.Count,1)
--     });
-- end

function M.UpdateProgress(self,percent)
    self.insts.Task.progress.Size=UDim2.fromScale(percent,1)
end

function M.UpdateTime(self,str)
    self.insts.Task.onLineTime.Text=str
end

function M.ClearTask(self)
    self.insts.Task.progress.Size=UDim2.fromScale(0,1)
    self.insts.Task.onLineTime.Text="????"
end

--更新免费次数
function M.FreeCount(self,count)
    count=count or 0
    print("------FreeCount---->:",count)
    self:FullText(self.insts.Free.count,{count})
end

function M.dtor(self)
	M.super.dtor(self);
end;

return M;